<template>
	<div class="info_box">
		<el-tabs v-model="activeName" class="demo-tabs">
			<el-tab-pane label="会议信息" name="1">
				<HyCard title="基本信息">
					<reUnitInfo :message="message" />
				</HyCard>
				<div class="mt-5"></div>
				<HyCard title="抽取设置">
					<reUnitExt :message="message" />
				</HyCard>
				<div class="mt-5"></div>
				<HyCard title="抽取结果">
					<reUnitOut :message="message" />
				</HyCard>
			</el-tab-pane>
			<el-tab-pane label="评审专家" name="2">
				<TableExpert :tableData="message?.expertList" />
			</el-tab-pane>
			<el-tab-pane label="评审机构" name="3">
				<TableInsti :tableData="message?.institutionList" />
			</el-tab-pane>
		</el-tabs>
		<div class="mt-5"></div>
		<HyCard v-show="activeName == '2'" title="评审意见">
			<HyForm
				v-if="routerData.tfOp == 'true'"
				:hyFormDefault="message"
				:hyFormConfig="hyFormConfig1"
				:hyFormFields="hyFormFields1"
				ref="hyFormRef1"
			/>
			<reUnitOpinion v-else :message="message" :activeName="activeName"></reUnitOpinion>
		</HyCard>
		<HyCard v-show="activeName == '3'" title="评审意见">
			<!-- hyFormDefault 回显 -->
			<HyForm
				v-if="routerData.tfOp == 'true'"
				:hyFormDefault="message"
				:hyFormConfig="hyFormConfig2"
				:hyFormFields="hyFormFields2"
				ref="hyFormRef2"
			/>
			<reUnitOpinion v-else :message="message" :activeName="activeName"></reUnitOpinion>
		</HyCard>
		<div v-if="['2', '3'].indexOf(activeName) != -1 && routerData.tfOp == 'true'" class="flex justify-center mt-10">
			<el-button type="primary" :loading="loading" @click="submit">保存</el-button>
		</div>
	</div>
</template>

<script lang="ts" setup>
import HyCard from '/@/views/digitalList/detail/components/Card.vue';
import reUnitInfo from './reUnitInfo.vue';
import reUnitExt from './reUnitExt.vue';
import reUnitOut from './reUnitOut.vue';
import reUnitOpinion from './reUnitOpinion.vue';
import HyForm from '/@/components/HyForm/index.vue';
import TableExpert from './TableExpert.vue';
import TableInsti from './TableInsti.vue';
import { updateReviewComments } from '/@/api/expertDatabase/evaluate';
import { toRefs, defineProps, ref, watch } from 'vue';
import { ElMessage } from 'element-plus';
const props = defineProps({
	message: {
		type: Object,
		default: () => {
			return {};
		},
	},
	//是否为意见上传
	routerData: {
		type: Object,
		default: () => {
			return {};
		},
	},
	//修改意见基础信息
	appInfo: {
		type: Object,
		default: () => {
			return {};
		},
	},
});
const activeName = ref('1');

//评审专家信息表单
const hyFormRef1: any = ref(null);
const hyFormFields1 = computed(() => {
	return {
		expertOpinionFileObj: {
			label: '意见上传',
			type: 'upload',
			required: false,
		},
		expertOpinionRemarkStr: {
			label: '备注',
			type: 'textarea',
			required: false,
		},
	};
});
//评审专家表单配置
const hyFormConfig1 = computed(() => {
	return {
		labelWidth: '100px',
		span: 24,
		offset: 0,
		type: 'submit',
	};
});
//评审机构信息表单
const hyFormRef2: any = ref(null);
const hyFormFields2 = computed(() => {
	return {
		institutionOpinionFileObj: {
			label: '意见上传',
			type: 'upload',
			required: false,
		},
		institutionOpinionRemarkStr: {
			label: '备注',
			type: 'textarea',
			required: false,
		},
	};
});
//评审机构配置
const hyFormConfig2 = computed(() => {
	return {
		labelWidth: '100px',
		span: 24,
		offset: 0,
		type: 'submit',
	};
});
const loading = ref(false);
const submit = (formEl: any) => {
	let data = {
		reviewMeetingId: message.value.baseInfo.id || '',
		appId: appInfo.value.appId || '',
		appCategory: appInfo.value.appCategory || '',
		expertOpinionFileObj: hyFormRef1.value.hyForm.expertOpinionFileObj,
		expertOpinionRemarkStr: hyFormRef1.value.hyForm.expertOpinionRemarkStr,
		institutionOpinionFileObj: hyFormRef2.value.hyForm.institutionOpinionFileObj,
		institutionOpinionRemarkStr: hyFormRef2.value.hyForm.institutionOpinionRemarkStr,
	};
	updateReviewComments(data)
		.then((res) => {
			loading.value = false;
			if (res.code == 0) {
				ElMessage({
					message: '保存成功',
					type: 'success',
				});
			}
		})
		.catch(() => {
			loading.value = false;
		});
};

const { message, routerData, appInfo } = toRefs(props);
</script>

<style lang="scss" scoped></style>
